#!/usr/bin/env python
# encoding: utf-8
"""
@author: youfeng
@email: youfeng243@163.com
@license: Apache Licence
@file: mq_model.py
@time: 2018/1/19 15:37
"""


# 发送到消息队列存储模型
class MqModel(object):
    # 网页库存储模型
    DETAIL_PAGE_MODEL = 'detail_page_model'
    # 网页库表名
    DETAIL_PAGE_TABLE = 'detail_page_table'

    # 网页库存储模型
    LIST_PAGE_MODEL = 'list_page_model'
    # 网页库表名
    LIST_PAGE_TABLE = 'list_page_table'

    # 种子库存储名称
    SEED_MODEL = 'seed_model'
    # 种子库表名
    SEED_TABLE = 'seed_table'

    # 工商缓存存储模型
    GS_CACHE_MODEL = 'gs_cache_model'

    # 年报缓存存储模型
    ANNUAL_CACHE_MODEL = 'annual_cache_model'

    def __init__(self, store_model=None):
        if not isinstance(store_model, dict):
            self.store_model = {}
        else:
            self.store_model = store_model

    # 添加详情页网页库信息
    def append_detail_page(self, table_name, page_model):
        self.store_model[self.DETAIL_PAGE_TABLE] = table_name
        self.store_model[self.DETAIL_PAGE_MODEL] = page_model

    # 获得详情页网页库信息
    def get_detail_page(self):
        return self.store_model.get(self.DETAIL_PAGE_TABLE), self.store_model.get(self.DETAIL_PAGE_MODEL)

    # 添加列表页网页库信息
    def append_list_page(self, table_name, page_model):
        self.store_model[self.LIST_PAGE_TABLE] = table_name
        self.store_model[self.LIST_PAGE_MODEL] = page_model

    # 获得列表页网页库信息
    def get_list_page(self):
        return self.store_model.get(self.LIST_PAGE_TABLE), self.store_model.get(self.LIST_PAGE_MODEL)

    # 添加种子库信息
    def append_seed(self, table_name, seed_model):
        self.store_model[self.SEED_TABLE] = table_name
        self.store_model[self.SEED_MODEL] = seed_model

    # 获得种子库信息
    def get_seed(self):
        return self.store_model.get(self.SEED_TABLE), self.store_model.get(self.SEED_MODEL)

    # 添加工商缓存信息
    def append_gs_cache(self, key, value):
        self.store_model[self.GS_CACHE_MODEL] = {
            'key': key,
            'value': value,
        }

    # 获得工商缓存信息
    def get_gs_cache(self):
        return self.store_model.get(self.GS_CACHE_MODEL)

    # 添加年报缓存信息
    def append_annual_cache(self, key, value):
        self.store_model[self.ANNUAL_CACHE_MODEL] = {
            'key': key,
            'value': value,
        }

    # 获得年报缓存信息
    def get_annual_cache(self):
        return self.store_model.get(self.ANNUAL_CACHE_MODEL)

    # 获得存储结构
    def get_store_model(self):
        return self.store_model
